package team.se.tms.util;

import team.se.tms.vo.Result;

/**
 * 结果返回封装工具类
 *
 * @author winkyle
 * @date 2018/11/15
 */
public class ResultUtil {

    /**
     * 封装一个结果
     *
     * @param msg 信息
     * @param object 数据
     * @return success true; code 0; msg msg; data object;
     * @create on 2018/11/15 by winkyle
     */
    public static Result success(String msg, Object object) {
        Result result = new Result();
        result.setSuccess(true);
        result.setCode(0);
        result.setMsg(msg);
        result.setData(object);
        return result;
    }

    /**
     * 封装一个结果
     *
     * @param msg 信息
     * @return success true; code 0; msg msg; data null;
     * @create on 2018/11/15 by winkyle
     */
    public static Result success(String msg) {
        return success(msg, null);
    }

    /**
     * 封装一个结果
     *
     * @param object 数据
     * @return success true; code 0; msg 查询成功; data object;
     * @create on 2018/11/15 by winkyle
     */
    public static Result success(Object object) {
        return success("查询成功", object);
    }

    /**
     * 封装一个结果
     *
     * @return success true; code 0; msg 成功; data null;
     * @create on 2018/11/15 by winkyle
     */
    public static Result success() {
        return success("成功");
    }

    /**
     * 封装一个结果
     *
     * @param code 信息码
     * @param msg 信息
     * @param object 数据
     * @return success false; code code; msg msg; data object;
     * @create on 2018/11/15 by winkyle
     */
    public static Result error(Integer code, String msg, Object object) {
        Result result = new Result();
        result.setSuccess(false);
        result.setCode(code);
        result.setMsg(msg);
        result.setData(object);
        return result;
    }

    /**
     * 封装一个结果
     *
     * @param code 信息码
     * @param msg 信息
     * @return success false; code code; msg msg; data null;
     * @create on 2018/11/15 by winkyle
     */
    public static Result error(Integer code, String msg) {
        return error(code, msg, null);
    }

    /**
     * 封装一个结果
     *
     * @param code 信息码
     * @return success false; code code; msg 失败; data null;
     * @create on 2018/11/15 by winkyle
     */
    public static Result error(Integer code) {
        return error(code, "失败");
    }
}
